package com.song.commonutils;

import com.baomidou.mybatisplus.extension.api.R;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * @author song
 * @data 2020/3/30
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultObj {
    @ApiModelProperty(value = "是否成功")
    private Boolean success;

    @ApiModelProperty(value = "返回码")
    private Integer code;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private Map<String, Object> data = new HashMap<String, Object>();

    public static final ResultObj LOGIN_SUCCESS = new ResultObj(20000,"登陆成功");
    public static final ResultObj LOGIN_ERROR = new ResultObj(-1,"登陆失败");

    public static final ResultObj DELETE_SUCCESS = new ResultObj(20000,"删除成功");
    public static final ResultObj DELETE_ERROR = new ResultObj(-1,"删除失败");

    public static final ResultObj ADD_SUCCESS = new ResultObj(20000,"添加成功");
    public static final ResultObj ADD_ERROR = new ResultObj(-1,"添加失败");

    public static final ResultObj UPDATE_SUCCESS = new ResultObj(20000,"更新成功");
    public static final ResultObj UPDATE_ERROR = new ResultObj(-1,"更新失败");

    public static final ResultObj DISPATCH_SUCCESS = new ResultObj(20000,"分配成功");
    public static final ResultObj DISPATCH_ERROR = new ResultObj(-1,"分配失败");

    public static final ResultObj RESET_SUCCESS = new ResultObj(20000,"重置成功");
    public static final ResultObj RESET_ERROR = new ResultObj(-1,"重置失败");

    public static final ResultObj PUBLISH_SUCCESS = new ResultObj(20000,"发布成功");
    public static final ResultObj PUBLISH_ERROR = new ResultObj(-1,"发布失败");

    public static ResultObj trueObj(String message){
        return new ResultObj(20000,message);
    }
    public static ResultObj falseObj(String message){
        return new ResultObj(-1,message);
    }

    //成功静态方法
    public static ResultObj ok() {
        ResultObj r = new ResultObj();
        r.setSuccess(true);
        r.setMessage("成功");
        r.setCode(20000);
        return r;
    }

    //失败静态方法
    public static ResultObj error() {
        ResultObj r = new ResultObj();
        r.setSuccess(true);
        r.setMessage("失败");
        r.setCode(-1);
        return r;
    }
    public ResultObj(Integer code, String message) {
        this.code = code;
        this.message = message;
    }


    public ResultObj data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public ResultObj data(Map<String, Object> map){
        this.setData(map);
        return this;
    }

    public ResultObj message(String message) {
        this.message = message;
        return this;
    }

    public ResultObj code(Integer code) {
        this.code = code;
        return this;
    }
}
